package cn.mapper;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import cn.pojo.Unit;
import cn.util.DBUtil;

public class UnitMapperImpl extends DBUtil implements UnitMapper {

	@Override
	public List<Unit> getAllUnit() {
		String sql = "select * from smbms_unit ;";
		List<Unit> list = new ArrayList<Unit>();
		Connection ct = getConnection();
		PreparedStatement ps = null;
		ResultSet st = null;
		try {
			ps = ct.prepareStatement(sql);
			st = ps.executeQuery();
			while (st.next()) {
				Unit u = new Unit();
				u.setId(st.getInt("id"));
				u.setUnitName(st.getString("unitName"));
				list.add(u);
			}
			return list;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			release(ct, ps, st);
		}
		return null;
	}

}
